package com.shicijiaoliu.service.impl;

import com.github.pagehelper.PageHelper;
import com.shicijiaoliu.mapper.Replypostmapper;
import com.shicijiaoliu.pojo.Replypost;
import com.shicijiaoliu.service.Replyservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Replypostserviceimpl implements Replyservice {
    @Autowired
    Replypostmapper replypostmapper;

    @Override
    public int getcount( long aId, long mId) {
        return replypostmapper.getcount(aId,mId);
    }


    @Override
    public List<Replypost> findBypage(int pagecount, int pagenumber, long aId, long mId) {
        int count = replypostmapper.getcount(0,0);
        int totalpage = (int) Math.ceil((double)count/pagenumber);
        if(pagecount>totalpage || pagecount <= 0){
            return null;
        }else{
            PageHelper.startPage(pagecount,pagenumber);
            return replypostmapper.findBypage(aId,mId);
        }
    }



    @Override
    public void delByid(long id) {
        replypostmapper.delByid(id);
    }

    @Override
    public Replypost findByid(long id) {
        return replypostmapper.findByid(id);
    }


    @Override
    public void jiajing(long rId) {
        String isjing = "是";
        if(replypostmapper.findByid(rId).getIsjing().equals(isjing))
            isjing = "否";
        replypostmapper.jiajing(rId,isjing);
    }

    @Override
    public List<Replypost> getlist() {
        return replypostmapper.getlist();
    }

    @Override
    public List<Replypost> findBymid(long mid) {
        return replypostmapper.findBymid(mid);
    }

    @Override
    public void add(Replypost rpost) {
        replypostmapper.add(rpost);
    }
}
